package cn.wgx.common.security.feign.module.sysuser;

import cn.wgx.common.entity.sys.SysUser;
import cn.wgx.common.security.client.config.entity.LoginAppUser;
import feign.hystrix.FallbackFactory;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.List;

/**
 * UserFeign 熔断器
 */
@Slf4j
@Component
public class UserFeignClientFallbackFactory implements FallbackFactory<SysUserFeign> {
	@Override
	public SysUserFeign create(Throwable throwable) {
		return new SysUserFeign() {


			@Override
			public LoginAppUser findCurrentUser(String mobile) {
				log.error("feign通过手机号查询用户异常:{}", mobile, throwable);
				return new LoginAppUser();
			}

			@Override
			public LoginAppUser findByUsername(String username) {
				log.error("feign通过用户名查询用户异常:{}", username, throwable);
				return new LoginAppUser() ;
			}

			@Override
			public LoginAppUser findByMobile(String mobile) {
				log.error("feign通过手机号查询用户异常:{}", mobile, throwable);
				return new LoginAppUser();
			}

			public List<SysUser> findUsersByUserIds(List<Integer> id){
				log.error("feign获取用户列表失败:{}", id, throwable);
				return new ArrayList<>();
			}
		};
	}
}
